package cn.gok.demo.base.web;

import cn.gok.demo.base.entity.BaseEntity;
import cn.gok.demo.base.service.BaseService;
import cn.gok.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Author: zhengyx
 * @Date: 2022/7/26 15:53
 * @Version 1.0
 */
public abstract class BaseController <S extends BaseService,T extends BaseEntity>{
    @Autowired
    S service;

    public abstract String getPerfix();

    @PostMapping("add")
    public String add(T entity){
//        entity.setCreateTime(new Date());
//        entity.setUpdateTime(new Date());
        service.save(entity);
        return "redirect:"+getPerfix();
    }

    @PostMapping("edit")
    public String edit(T entity){
        service.update(entity);
        return "redirect:"+getPerfix();
    }

    @RequestMapping("delete")
    public String delete(T entity){
        service.delete(entity.getId());
        return "redirect:"+getPerfix();
    }
    @RequestMapping("list")
    public void list(T entity){
        service.list();
    }


}
